package servlet;

/**
 * @author 鲁新茹
 * @date 2022/3/12
 */


import hbase.HbaseUtil;
import hbase.Student;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

@WebServlet("/studentAdd")
public class HbaseAdd extends HttpServlet{

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String id = req.getParameter("studentId");
        String name = req.getParameter("name");
        String date =  req.getParameter("date");
        String contact = req.getParameter("cn");
        String semester=req.getParameter("semester");
        String status = req.getParameter("studentStatus");

        ArrayList<Student> studentArrayList = new ArrayList<>();
        Student student = new Student();
        student.setStudentId(id);
        student.setName(name);
        student.setDate(date);
        student.setCn(contact);
        student.setSemester(semester);
        student.setStudentStatus(status);
        studentArrayList.add(student);


        HbaseUtil hbaseAddUtil = new HbaseUtil();
        String obj_value = "";
        try{

            obj_value = hbaseAddUtil.insertinfo("niit01","2181","Student",studentArrayList);
        }catch (Exception e){
            e.printStackTrace();
        }

        resp.setContentType("text/html;charset=utf-8");
        PrintWriter pw = resp.getWriter();
        pw.write("<h1>"+ obj_value);



    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    }
}